#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>



int main(void)
{
    int fd;
    int ret;
    ret = mkfifo("./my_fifo", 0666);//创建命名管道
    if(ret != 0)
    {
        perror("mkfifo");
        exit(1);
    }
    printf("before open\n");
    fd = open("my_fifo", O_RDONLY);//等着只
    if(fd < 0)
    {
        perror("open fifo");
    }
    printf("after open\n");
    printf("before read\n");
    char recv[100] = {0};
    //读数据，命名管道没数据时会阻塞，有数据时就取出来
    read(fd, recv, sizeof(recv));
    printf("read from my_fifo buf=[%s]\n", recv);
    return 0;

}

